var target        = Argument("target", "Default");
var configuration = Argument("configuration", "Debug");
var releaseNumber = Argument("releaseNumber", "");
var publish       = HasArgument("publish");

var solution                 = "cuda.sln";
var nuspecFile               = "Sustainalytics.CUDA.nuspec";
var octopusDeployProjectName = "GA.Cuda";
var nugetSource              = "http://10.120.120.11/nuget/";
var nugetApiKey              = "75C3305A-CE30-403F-93BF-FE18C570231E";
var nugetPackageDir          = "./artifacts";
var buildDir                 = "../Bin/Cuda/" + configuration + "/x64";

Task("Clean")
  .Does(() => {
    EnsureDirectoryExists(nugetPackageDir);
    CleanDirectory(buildDir);
    CleanDirectory(nugetPackageDir);
  });

Task("Build")
  .IsDependentOn("Clean")
  .Does(() => MSBuild(solution, new MSBuildSettings {
    NodeReuse = false,
    Configuration = configuration,
    PlatformTarget = PlatformTarget.x64,
  }));

Task("NuGetPack")
  .Does(() => {
    var nuGetPackSettings = new NuGetPackSettings {
      BasePath = buildDir,
      OutputDirectory = Directory(nugetPackageDir),
      Version = releaseNumber,
      ArgumentCustomization = args => args.Append("-Prop Configuration=" + configuration),
    };
    NuGetPack(nuspecFile, nuGetPackSettings);
  });

Task("NuGetPush")
  .WithCriteria(HasArgument("releaseNumber"))
  .WithCriteria(publish)
  .Does(() => {
    var packages = GetFiles(nugetPackageDir+"/*.nupkg");
    var nuGetPushSettings = new NuGetPushSettings {
      Source = nugetSource,
      ApiKey = nugetApiKey,
    };
    NuGetPush(packages, nuGetPushSettings);
  });

Task("Default")
  .IsDependentOn("Build")
  .IsDependentOn("NuGetPack")
  .IsDependentOn("NuGetPush");

RunTarget(target);
